package cn.qy.java.base;

import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

/**
 * @author kai
 */
public class Application {

    public static void main(String[] args) throws UnsupportedEncodingException {
        System.out.println("Java 乱码测试");

        System.out.println(new String("Java 乱码测试".getBytes()));
        System.out.println(new String("Java 乱码测试".getBytes(), "gbk"));
        System.out.println(new String("Java 乱码测试".getBytes(), StandardCharsets.UTF_8));

        // OK
        System.out.println(new String("Java 乱码测试".getBytes(StandardCharsets.UTF_8)));
        // OK
        System.out.println(new String("Java 乱码测试".getBytes(StandardCharsets.UTF_8), "gbk"));
        System.out.println(new String("Java 乱码测试".getBytes(StandardCharsets.UTF_8), StandardCharsets.UTF_8));

        System.out.println(new String("Java 乱码测试".getBytes("gbk")));
        System.out.println(new String("Java 乱码测试".getBytes("gbk"), "gbk"));
        System.out.println(new String("Java 乱码测试".getBytes("gbk"), StandardCharsets.UTF_8));

        System.out.println("defaultCharset = " + Charset.defaultCharset());
        System.out.println("file.encoding = " + System.getProperty("file.encoding"));
        System.out.println("user.dir = " + System.getProperty("user.dir"));
        System.out.println("user.home = " + System.getProperty("user.home"));
        System.out.println("user.country = " + System.getProperty("user.country"));
        System.out.println("user.language = " + System.getProperty("user.language"));
        System.out.println("java.home = " + System.getProperty("java.home"));

        System.out.println("ContextClassLoader.resource = " + Thread.currentThread().getContextClassLoader().getResource("."));
        System.out.println("class.resource = " + Application.class.getResource("/").getPath());
    }
}
